package com.yimingkeji.elasticsearch.rest;

import com.yimingkeji.elasticsearch.dao.UserRepository;
import com.yimingkeji.elasticsearch.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Describe:
 * @Auther: zhenlong.yang
 * @Date: 2018/12/4 13:23
 */
@RestController
@RequestMapping("/user")
public class UserResource {


    @Autowired private UserRepository userRepository;
    @PostMapping("")
    public User save(@RequestBody User user){
        return userRepository.save(user);
    }

    @GetMapping("")
    public Iterable<User> findAll(){
        return userRepository.findAll();
    }

    @GetMapping("/{name}")
    public User findOne(@PathVariable String name){
        return userRepository.findByName(name);
    }
}
